﻿#include "AddEmployeeDialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QFrame>
#include <QIcon>

AddEmployeeDialog::AddEmployeeDialog(QWidget* parent) : QDialog(parent)
{
    setWindowTitle(tr("新增员工"));
    setFixedSize(450, 350); // 固定对话框大小
    setStyleSheet(
        "QLineEdit, QDateEdit {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  color: black;"
        "}"
        "QPushButton {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  background-color: #0093D1;"
        "  color: white;"
        "}"
        "QComboBox {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  color: black;"
        "}"
    );
    QLabel* titleLabel = new QLabel(tr("新增员工信息"), this);
    titleLabel->setAlignment(Qt::AlignCenter);
    titleLabel->setStyleSheet("font-size: 24px; font-weight: bold;");

    QFrame* line1 = new QFrame(this);
    line1->setFrameShape(QFrame::HLine);
    line1->setFrameShadow(QFrame::Sunken);

    QLabel* accountLabel = new QLabel(tr("账号"), this);
    accountLabel->setStyleSheet("font-size: 18px; font-weight: bold;");
    accountLineEdit = new QLineEdit(this);
    accountLineEdit->setPlaceholderText(tr("输入账号"));
    accountLineEdit->setClearButtonEnabled(true);
    accountLineEdit->setStyleSheet("font-size: 18px; font-weight: bold;");

    QLabel* passwordLabel = new QLabel(tr("密码"), this);
    passwordLabel->setStyleSheet("font-size: 18px; font-weight: bold;");
    passwordLineEdit = new QLineEdit(this);
    passwordLineEdit->setPlaceholderText(tr("输入密码"));
    passwordLineEdit->setEchoMode(QLineEdit::Password);
    passwordLineEdit->setClearButtonEnabled(true);
    passwordLineEdit->setStyleSheet("font-size: 18px; font-weight: bold;");

    QLabel* positionLabel = new QLabel(tr("职位"), this);
    positionLabel->setStyleSheet("font-size: 18px; font-weight: bold;");
    positionComboBox = new QComboBox(this);
    positionComboBox->addItem(QIcon(":/icons/sales.png"), tr("销售管理员"));
    positionComboBox->addItem(QIcon(":/icons/stock.png"), tr("库存管理员"));
    positionComboBox->addItem(QIcon(":/icons/finance.png"), tr("财务管理员"));
    positionComboBox->setStyleSheet("font-size: 18px; font-weight: bold;");

    confirmButton = new QPushButton(tr("确认新增员工"), this);
    confirmButton->setStyleSheet("background-color: #0093D1; color: white; font-size: 20px; font-weight: bold; padding: 10px;");
    cancelButton = new QPushButton(tr("取消"), this);
    cancelButton->setStyleSheet("background-color: #0093D1; color: white; font-size: 20px; font-weight: bold; padding: 10px;");

    QVBoxLayout* mainLayout = new QVBoxLayout(this);

    // 创建标题布局
    QVBoxLayout* titleLayout = new QVBoxLayout;
    titleLayout->addWidget(titleLabel);
    titleLayout->addWidget(line1);

    // 创建账户布局
    QHBoxLayout* accountLayout = new QHBoxLayout;
    accountLayout->addWidget(accountLabel);
    accountLayout->addWidget(accountLineEdit);

    // 创建密码布局
    QHBoxLayout* passwordLayout = new QHBoxLayout;
    passwordLayout->addWidget(passwordLabel);
    passwordLayout->addWidget(passwordLineEdit);

    // 创建职位布局
    QHBoxLayout* positionLayout = new QHBoxLayout;
    positionLayout->addWidget(positionLabel);
    positionLayout->addWidget(positionComboBox);

    // 创建按钮布局
    QHBoxLayout* buttonLayout = new QHBoxLayout;
    buttonLayout->addWidget(confirmButton);
    buttonLayout->addWidget(cancelButton);

    // 将各部分布局添加到主布局中，并调整比例
    mainLayout->addLayout(titleLayout, 1);  // 标题部分占20%
    mainLayout->addLayout(accountLayout, 2);  // 账号部分占40%
    mainLayout->addLayout(passwordLayout, 2);  // 密码部分占40%
    mainLayout->addLayout(positionLayout, 2);  // 职位部分占40%
    mainLayout->addStretch(1);  // 添加一个拉伸因子来占据剩余的空间
    mainLayout->addLayout(buttonLayout, 1);  // 按钮部分占20%

    setLayout(mainLayout);

    connect(cancelButton, &QPushButton::clicked, this, &AddEmployeeDialog::reject);
    connect(confirmButton, &QPushButton::clicked, this, &AddEmployeeDialog::accept);
}

QLineEdit* AddEmployeeDialog::getAccountLineEdit() const {
    return accountLineEdit;
}

QLineEdit* AddEmployeeDialog::getPasswordLineEdit() const {
    return passwordLineEdit;
}

QComboBox* AddEmployeeDialog::getPositionComboBox() const {
    return positionComboBox;
}
